package cn.ml.entity;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collector;

public class Student implements Comparable {
    // 学号
    private int id;
    //名称
    private String name;
    // 性别
    private String sex;
    //年龄
    private Integer age;
    //身高
    private Double height;
    //出生日期
    private LocalDate birthday;
    // 资产
    private BigDecimal property;

    public Student() {
    }

    public Student(int id, String name, String sex, Integer age, Double height, LocalDate birthday, BigDecimal property){
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.height = height;
        this.birthday = birthday;
        this.property = property;
    }
    @Override
    public String toString(){
        String info = String.format("%s\t\t%s\t\t%s\t\t%s\t\t\t%s\t\t%s\t\t%s",this.id,this.name,this.sex.toString(),this.age.toString(),this.height.toString(),birthday.toString(),this.property+"元");
        return info;
    }

    public static void printStudents(List<Student> students){
        System.out.println("[学号]\t\t[姓名]\t\t[性别]\t\t[年龄]\t\t[身高]\t\t[生日]\t\t[资产]");
        System.out.println("----------------------------------------------------------");
        students.forEach(s->System.out.println(s.toString()));

        //两种写法结果一样
        /*for (Student student:students){
            System.out.println(student.toString());
        }*/

        System.out.println(" ");
    }


    public int compareTo(Student ob) {
        return this.age.compareTo(ob.getAge());
        //return 1;
    }

    public static List<Student> getStudentList() {
        List<Student> studentList = new ArrayList<>();
        studentList.add(new Student(1,"张三1","男",18,1.76,LocalDate.of(2001,3,23), new BigDecimal(1111)));
        studentList.add(new Student(2,"张三2","女",18,1.61,LocalDate.of(2001,6,3), new BigDecimal(2222)));
        studentList.add(new Student(3,"张三3","女",19,1.82, LocalDate.of(2000,3,11), new BigDecimal(3333)));
        studentList.add(new Student(4,"张三4","男",17,1.67,LocalDate.of(2002,10,18), new BigDecimal(4444)));
        studentList.add(new Student(5,"李四1","男",18,1.76,LocalDate.of(2001,3,23), new BigDecimal(1111)));
        studentList.add(new Student(6,"李四2","女",18,1.61,LocalDate.of(2001,6,3), new BigDecimal(2222)));
        studentList.add(new Student(7,"李四3","女",19,1.82, LocalDate.of(2000,3,11), new BigDecimal(3333)));
        studentList.add(new Student(8,"李四4","男",17,1.67,LocalDate.of(2002,10,18), new BigDecimal(4444)));
        return studentList;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String gender) {
        this.sex = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        if(age >= 18 && age <= 25){
            this.age = age;
        }else{
            throw new RuntimeException("年龄超出了范围");
        }
    }

    public Double getHeight() {
        return height;
    }

    public void setHeight(Double height) {
        this.height = height;
    }

    public LocalDate getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDate birthday) {
        this.birthday = birthday;
    }

    public BigDecimal getProperty() {
        return property;
    }

    public void setProperty(BigDecimal property) {
        this.property = property;
    }

    @Override
    public int compareTo(Object obj) {
        Student student=(Student) obj;
        if(this.id==student.id){
            return 0;			//如果学号相同，那么两者就是相等的
        }else if(this.id>student.getId()){
            return 1;			//如果这个学生的学号大于传入学生的学号
        }else{
            return -1;			//如果这个学生的学号小于传入学生的学号
        }
    }
}
